package com.bos.dao.impl;

import com.bos.dao.SekolahDAO;
import com.bos.domain.Sekolah;
import com.bos.util.enums.JenjangSekolah;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityNotFoundException;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Latief
 * Date: 3/15/11
 * Time: 9:36 PM
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class SekolahDAOImpl extends GenericDAOImpl<Sekolah> implements SekolahDAO {

    public SekolahDAOImpl() {
        super(Sekolah.class);
    }

    @Override
    public Sekolah findByNpsn(String npsn) throws DataAccessException, EntityNotFoundException {
        return (Sekolah) this.entityManager.createQuery("SELECT o FROM Sekolah o WHERE o.npsn = :npsn").setParameter("npsn", npsn).getSingleResult();
    }

    public List<Sekolah> findByJenjangSekolah(JenjangSekolah jenjangSekolah)   throws DataAccessException, EntityNotFoundException {
        return entityManager.createQuery("SELECT o FROM Sekolah o WHERE o.jenjangSekolah = :jenjangSekolah")
                .setParameter("jenjangSekolah", jenjangSekolah)
                .getResultList();
    }
}
